#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int n, m;
struct node
{
	int l, r;
	int ma;
}tree[N<<2];
int w[N];
void pushup(int u)
{
	tree[u].ma = max(tree[u << 1].ma, tree[u << 1 | 1].ma);
}
void build(int u, int l, int r)
{
	if (l == r) {
		tree[u] = { l,r,w[l] };
		return;
	}
	else {
		tree[u] = { l,r };
		int mid = l + r >> 1;
		build(u << 1, l, mid);
		build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}

void modify(int u, int x, int v)
{
	if (tree[u].l == tree[u].r) {
		tree[u].ma = v;
	}
	else {
		int mid = tree[u].l + tree[u].r >> 1;
		if (x <= mid) {
			modify(u << 1, x, v);
		}
		else {
			modify(u << 1 | 1, x, v);
		}
		pushup(u);
	}
}

int query(int u, int l,int r)
{
	if (tree[u].l >= l && tree[u].r <= r) {
		return tree[u].ma;
	}
	else {
		int mid = tree[u].l + tree[u].r;
		int ans = 0;
		if (l <= mid) {
			ans=query(u << 1, l, r);
		}
		if (mid <= r) {
			ans = max(ans, query(u << 1 | 1, l, r));
		}
		return ans;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> w[i];
	build(1, 1, n);
	while (m--) {
		string s;
		int l, r;
		cin >> s >> l >> r;
		if (s[0] == 'Q') {
			cout << query(1, l, r) << endl;
		}
		else {
			modify(1, l, r);
		}
	}
	return 0;
}